/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.util.ArrayList;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 *
 * @author ImNotPro
 */
public class WorkingDirectory {

    private String Path;
    private String Dir;
    private ArrayList<Data> StructDir;

    public WorkingDirectory() {
        //
    }

    public WorkingDirectory(JSONObject json) throws JSONException {
        //Set data
        this.Dir = json.getString("name");
        if (json.has("path")) {
            this.Path = json.getString("path");
        }

        //Get array
        this.StructDir = new ArrayList<Data>();
        JSONArray Files = json.getJSONArray("content");

        //Add to list of path
        for (int i = 0; i < Files.length(); i++) {
            this.StructDir.add(new Data(Files.getJSONObject(i)));
        }
    }

    public JSONObject getJSON() {
        //Create object
        JSONObject JSON = new JSONObject();

        try {

            //Create JSON array
            JSONArray Files = new JSONArray();
            for (int i = 0; i < this.StructDir.size(); i++) {
                Files.put(this.StructDir.get(i).getJSON());
            }

            //Add data
            if (this.Path != null) {
                JSON.put("path", this.Path);
            }
            JSON.put("name", this.Dir);
            JSON.put("content", Files);
        } catch (JSONException ex) {
        }

        //Return json string
        return JSON;
    }

    /**
     * @return the Path
     */
    public String getPath() {
        return Path;
    }

    /**
     * @param Path the Path to set
     */
    public void setPath(String Path) {
        this.Path = Path;
    }

    /**
     * @return the Dir
     */
    public String getDir() {
        return Dir;
    }

    /**
     * @param Dir the Dir to set
     */
    public void setDir(String Dir) {
        this.Dir = Dir;
    }

    /**
     * @return the StructDir
     */
    public ArrayList<Data> getStructDir() {
        return StructDir;
    }

    /**
     * @param StructDir the StructDir to set
     */
    public void setStructDir(ArrayList<Data> StructDir) {
        this.StructDir = StructDir;
    }
}
